package org.agony2d.gpu.core {
	import org.agony2d.core.agony_internal;
	import org.agony2d.debug.Logger;
	import org.agony2d.gpu.FusionAA;
	import org.agony2d.gpu.supportClasses.buffers.BuffersManager;
	import org.agony2d.gpu.supportClasses.programs.ProgramProxy;
	import org.agony2d.gpu.supportClasses.textures.FullTexture;
	import org.agony2d.gpu.supportClasses.textures.TextureManager;
	import org.agony2d.gpu.supportClasses.textures.TextureProxy;
	import org.agony2d.notify.AEvent;
	
	use namespace agony_internal;
	
public class GroupAA extends BranchAA {
	
	[Inline]
	final agony_internal function setting( fullTexName:String, tinted:Boolean, smoothing:Boolean ) : void {
		m_fullTex = TextureManager.g_texList[fullTexName]
		if (!m_fullTex) {
			Logger.reportError(this, "constructor", "Not existed full texture: (" + fullTexName + ")...!!")
		}
		m_program = ProgramProxy.retrieve(tinted, smoothing, (m_fullTex as FullTexture).m_mipmapEnabled)
	}
	
	[Inline]
	final agony_internal function doFinishPrevGroup() : void {
		if (BuffersManager.g_currGroup) {
			m_prevGroup    =  BuffersManager.g_currGroup
			m_prevFullTex  =  BuffersManager.g_currFullTex
			m_prevProgram  =  BuffersManager.g_currProgram
			BuffersManager.goFinishAll()
		}
	}
	
	[Inline]
	final agony_internal function doResumePrevGroup() : void {
		if (m_prevGroup) {
			BuffersManager.g_currGroup    =  m_prevGroup
			BuffersManager.g_currFullTex  =  m_prevFullTex
			BuffersManager.g_currProgram  =  m_prevProgram
			m_prevGroup                   =  null
		}
		else {
			BuffersManager.g_currGroup = null
		}
	}
	
	
	agony_internal var m_prevGroup:GroupAA
	agony_internal var m_prevFullTex:FullTexture
	agony_internal var m_program:ProgramProxy
	agony_internal var m_prevProgram:ProgramProxy
	
	
	override agony_internal function attach( parent:NodeAA ) : void {
		var node:NodeAA
		
		if (parent == this) {
			Logger.reportError(this, "attach", "Node can't be added to self...!!")
		}
		if (m_parent) {
			node = parent.m_parent
			while (node) {
				if (node == this) {
					Logger.reportError(this, "attach", "无法将对象添加为自身的子对象（或孙对象）的子对象...!!")
				}
				node = node.m_parent
			}
			m_parent.removeNode(this)
			m_altered = true
		}
		m_parent = parent
		m_world = parent.m_world
	}
}
}